/*
 * @lc app=leetcode.cn id=86 lang=java
 *
 * [86] 分隔链表
 */

// @lc code=start
/* *
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    //感觉也不难啊，为啥是中等难度
    public ListNode partition(ListNode head, int x) {
        ListNode low = new ListNode(0);
        ListNode high = new ListNode(0);
        ListNode t1 = low;//初始位置
        ListNode t2 = high;

        while(head!=null){
            if(head.val<x){
                low.next = new ListNode(head.val);
                low = low.next;
            }else{//大于或等于x的情况
                high.next = new ListNode(head.val);
                high = high.next;
            }
            head = head.next;
        }
        low.next = t2.next;
        return t1.next;
    }
}
// @lc code=end

